clear all
macro drop all
set more off
set type double

** This will be the regression for adjacent border counties 
use qwi_laus_county_level.dta

* Some preliminaries
gen str5 temp1 = string(statecountycode, "%05.0f")
gen statecode = substr(temp1,1,2)
destring statecode, replace
drop temp1

/*drop DE from the dataset all-together */
drop if statecode==10
drop if yearqtr>=tm(2017q1)
/* ban  = 1 for states after they pass the ban, only for non-exempt occupations */

gen ban = 0

replace ban= 1 if (statecode==6 & yearqtr>=tq(2012q1)) | ///
(statecode==8 & yearqtr>=tq(2013q3)) | (statecode==9 & yearqtr>=tq(2011q4)) | ///
(statecode==10 & yearqtr>=tq(2014q2)) | (statecode==15 & yearqtr>=tq(2009q3)) | ///
(statecode==17 & yearqtr>=tq(2011q1)) | (statecode==24 & yearqtr>=tq(2011q4)) | ///
(statecode==32 & yearqtr>=tq(2013q4)) | (statecode==41 & yearqtr>=tq(2010q2)) | ///
(statecode==50 & yearqtr>=tq(2012q3)) | (statecode==53 & yearqtr>=tq(2007q3))
xtset statecountycode yearqtr 

gen log_ur = log(unemployment_rate)

reghdfe log_ur ban, /// 
absorb(yearqtr statecountycode) vce (robust)
outreg2 using table_5.xls, dec(3) replace

clear

** We now run the state-level regressions for unemployment flows

use state_flows.dta

drop if (time>=tq(2017q1) | time<tq(2005q1))
/* ban  = 1 for states after they pass the ban, only for non-exempt occupations */

gen ban = 0

replace ban= 1 if (state==6 & time>=tq(2012q1)) | ///
(state==8 & time>=tq(2013q3)) | (state==9 & time>=tq(2011q4)) | ///
(state==10 & time>=tq(2014q2)) | (state==15 & time>=tq(2009q3)) | ///
(state==17 & time>=tq(2011q1)) | (state==24 & time>=tq(2011q4)) | ///
(state==32 & time>=tq(2013q4)) | (state==41 & time>=tq(2010q2)) | ///
(state==50 & time>=tq(2012q3)) | (state==53 & time>=tq(2007q3))
xtset state time 

* Gen outcome variables
gen log_EU = log(hr_EU)
gen log_UE = log(hr_UE)

reghdfe log_EU ban, /// 
absorb(state time) vce (cluster state)
outreg2 using table_5.xls, dec(3) append

reghdfe log_UE ban, /// 
absorb(state time) vce (cluster state)
outreg2 using table_5.xls, dec(3) append

clear

* Next is the county level regression using Hagedorn et al. data

use final_jfr_data.dta 

gen strcc = string(fipsnumeric,"%05.0f")
gen statecode = substr(strcc,1,2)
destring statecode, replace

gen date = ym(year,month)
format date %tm

/*drop DE from the dataset all-together */
drop if statecode==10
drop if date>=tm(2017m1)
/* ban  = 1 for states after they pass the ban, only for non-exempt occupations */

rename fipsnumeric geography
gen ban = 0

replace ban= 1 if (statecode==6 & date>=tm(2012m1)) | ///
(statecode==8 & date>=tm(2013m7)) | (statecode==09 & date>=tm(2011m10)) | ///
(statecode==10 & date>=tm(2014m5)) | (statecode==15 & date>=tm(2009m7)) | ///
(statecode==17 & date>=tm(2011m1)) | (statecode==24 & date>=tm(2011m10)) | ///
(statecode==32 & date>=tm(2013m10)) | (statecode==41 & date>=tm(2010m4)) | ///
(statecode==50 & date>=tm(2012m7)) | (statecode==53 & date>=tm(2007m7))

xtset geography date

reghdfe jfrm ban, absorb(geography date) vce(cluster statecode)
outreg2 using table_5.xls, dec(3) append






